<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *打卡记录
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'已开通城市列表'),
);
if($_RQ['op']=='list'){
	$type=intval($_RQ['type']);
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['cityname'])){
		$params2=array('uniacid'=>$_SESSION['uniacid']);
		$params2['name like']='%'.trim($_RQ['cityname']).'%';
		$city_ids=pdo_getall('jy_huolala_city',$params2,'city_id','city_id');
		$params['city_id']=$city_ids?array_keys($city_ids):-1;
		$return['params']['cityname']=$_RQ['cityname'];
	}
	if(!empty($_RQ['name'])){
		$params['name like']='%'.trim($_RQ['name']).'%';
		$return['params']['name']=$_RQ['name'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_huolala_city',$params,array($pindex,$psize),$total,$fields,'','is_hot desc,id asc');
	foreach($list as &$item){
		$item['chenum']=pdo_count('jy_huolala_che',array('uniacid'=>$_SESSION['uniacid'],'city_id'=>$item['city_id']));
		$item['lat_lng']=json_decode($item['lat_lng'],true);
		$item['lat_lng']='纬度'.$item['lat_lng']['lat'].'经度'.$item['lat_lng']['lon'];
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'name','title'=>'城市名称','type'=>'string'),
			array('name'=>'name_en','title'=>'城市en','type'=>'string'),
			array('name'=>'city_id','title'=>'城市ID','type'=>'string'),
			array('name'=>'adcode','title'=>'区域代码','type'=>'string'),
			array('name'=>'lat_lng','title'=>'经纬度','type'=>'string'),
			array('name'=>'is_hot','title'=>'是否热门','type'=>'radio','options'=>'is_hot'),
			array('name'=>'chenum','title'=>'车型数量','type'=>'string'),
		),'batch'=>array(
			array('type'=>'post','url'=>'/city/updata/','title'=>'同步已开通城市'),
		),'action'=>array(
			array('type'=>'post','op'=>'upche','title'=>'获取城市可选车型信息'),
		)),
		'search'=>array(
			array('name'=>'name','width'=>15,'title'=>'城市名称','type'=>'string'),
		)
	);
	$return['is_hot']=array('否','是');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='updata'){
	$this->model('city')->upcity();
	exi('同步已开通城市成功！');
}
if($_RQ['op']=='upche'){
	$id=$_RQ['id'];
	$city_id=pdo_getcolumn('jy_huolala_city',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']),'city_id');
	$this->model('city')->upche($city_id);
	exi('获取城市可选车型信息成功！');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_huolala_city',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}
